package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolDemo {
    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(3);

        for (int i = 1;i<=5;i++){
            System.out.println("线程池交付一个任务");
            service.execute(() -> {
                Thread t = Thread.currentThread();
                System.out.println(t.getName()+"且正在执行任务");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(t.getName()+"结束任务");
            });
        }

        service.shutdown();
    }
}
